﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zeus.Thunder.Core;
using System.Xml.Linq;
using System.IO;

namespace SharpTrainer.Linq
{
    class LinqToXmlTest : ITestCase
    {
        public void Run()
        {
            //string dir = AppDomain.CurrentDomain.BaseDirectory;
            string fileName = Path.Combine(Path.GetFullPath("..//..//"), "Linq//data.xml");
            
            XDocument doc = XDocument.Load(fileName);

            var filtered = from p in doc.Descendants("Product")
                           join s in doc.Descendants("Supplier")
                           on (int)p.Attribute("SupplierID")
                           equals (int)s.Attribute("SupplierID")
                           where (decimal)p.Attribute("Price") > 10
                           orderby (string)s.Attribute("Name"),
                           (string)p.Attribute("Name")
                           select new
                           {
                               SupplierName = (string)s.Attribute("Name"),
                               ProductName = (string)p.Attribute("Name")
                           };

            foreach (var v in filtered)
            {
                Console.WriteLine("Supplier={0}; Product={1}",
                    v.SupplierName, v.ProductName);
            }
        }
    }
}
